import 'package:flutter/material.dart';
import 'package:hi_flutter/animate/logo.dart';
import 'package:hi_flutter/app_page.dart';

class GrowTransition extends StatelessWidget {
  const GrowTransition({Key? key, required this.child, required this.animation})
      : super(key: key);

  final Widget child;
  final Animation<double> animation;

  @override
  Widget build(BuildContext context) {
    return Center(
      child: AnimatedBuilder(
        animation: animation,
        builder: (BuildContext context, Widget? child) {
          return SizedBox(
            height: animation.value,
            width: animation.value,
            child: child,
          );
        },
        child: child,
      ),
    );
  }
}

class AnimatePage4 extends StatefulWidget {
  const AnimatePage4({Key? key}) : super(key: key);

  @override
  AnimatePage4State createState() => AnimatePage4State();
}

class AnimatePage4State extends State<AnimatePage4> with SingleTickerProviderStateMixin {
  late Animation<double> animation;
  late AnimationController controller;

  @override
  initState() {
    super.initState();
    controller = AnimationController(
        duration: const Duration(milliseconds: 2000), vsync: this);
    final CurvedAnimation curve =
        CurvedAnimation(parent: controller, curve: Curves.easeIn);
    animation = Tween(begin: 0.0, end: 300.0).animate(curve);
    controller.forward();
  }

  @override
  Widget build(BuildContext context) {
    return AppPage(
      body: GrowTransition(
        animation: animation,
        child: const LogoWidget(),
      ),
    );
  }

  @override
  dispose() {
    controller.dispose();
    super.dispose();
  }
}
